var http = require('http');
var querystring = require('querystring');

var allmess={
    CompanyId:'0010',
    Source:'wyc1',
    IPCType:'baseinfoVehicle',
    baseinfoVehicle:
        [
            { "CompanyId":"0901","Address":"370303","VehicleNo":"鲁C3532210","PlateColor":"蓝色","Seats":45,"Brand":"车辆厂牌","Model":"大众","VehicleType":"新宝来","OwnerName":"张三","VehicleColor":"绿色","EngineId":"发动机号23","VIN":"VIN码332","CertifyDateA":"20180504","FuelType":"石油","EngineDisplace":"2","PhotoId":"","Certificate":"*运输证字号513","TransAgency":"输证发证机构45","TransArea":"山东淄博","TransDateStart":"20180504","TransDateStop":"20180504","CertifyDateB":"20180504","FixState":"2","NextFixDate":"20190504","CheckState":"年度审验状","FeePrintId":"发票打印设备序列号45","GPSBrand":"卫星定位装置品牌暗示3","GPSModel":"卫星定位装置型号33","GPSIMEI":"卫星定位装置IMEI号强3","GPSInstallDate":"20170504","RegisterDate":"20170504","CommercialType":1,"FareType":"运价类型编码asa","State":1,"Flag":1,"UpdateTime":20180422152036},

        ]

};

/*
for(var j=0;j<3000;j++)
{
    var item={ "CompanyId":"0010","VehicleNo":"6002"+j,"VehicleRegionCode":"370031","PositionTime":"1524321478","Longitude":"118.234",        "Latitude":"36.234","Speed":"29","Direction":"81","Elevation":"31","Mileage":"","Encrypt":"","WarnStatus":"","VehStatus":"","BizStatus":"","OrderId":"003"};
    allmess["positionVehicle"].push(item);
}
*/

var contents = JSON.stringify(allmess);

var buf = new Buffer(contents,'utf8');

var options = {
    host:'127.0.0.1',
    // path:'/api.php/Node/index', port:8001,
    path:'/api.php/baseinfo/vehicle',  port:8001,
    method:'POST',
    headers:{
        'Content-Type':'application/json',
        'Content-Length':buf.length
    }
}

var req = http.request(options, function(res){
    res.setEncoding('utf8');
    res.on('data',function(data){
        console.log("data:",data);   //一段html代码
    });
});

req.on("timeout", function() {
    console.log("timeout received");
    if (req.res) {
        req.res.emit("abort");
    }

    req.abort();
});


//console.log(contents.toString('binary'));
//var buf = new Buffer(contents.toString('binary'),'binary');
req.write(buf);
req.end;